package ssw.game;

import ssw.game.engine.GameDictionary;

public class Checks {
	public static final Checks STARTS_WITH_WORD = new Checks(When.STARTS_WITH_WORD, "");
	public static final Checks ENDS_WITH_AN_S = new Checks(When.ENDS_WITH_LETTER, "S");
	
	public static enum When {
		ENDS_WITH_LETTER, STARTS_WITH_WORD;
	}
	
	public boolean accept(String word, GameDictionary dictionary)  {
		if (When.ENDS_WITH_LETTER == when)  {
			return word.endsWith(singleLetter);
		}
		else if (When.STARTS_WITH_WORD == when)  {
			String prefix = word.substring(0, word.length() - 1);
			return dictionary.contains(prefix);
		}
		
		return true;
	}
	
	private final String singleLetter;
	private final When when;
	
	public Checks(When when, String letter)  {
		super();
		this.when = when;
		this.singleLetter = letter;
	}
}
